//
//  SAFeedbackProductConsoultViewController.m
//  SunOn
//
//  Created by mc on 2017/5/4.
//  Copyright © 2017年 NeoZhang. All rights reserved.
//  产品咨询界面

#import "SAFeedbackProductConsoultViewController.h"
#import "SAFeedbackConsoultCell.h"//重用咨询界面cell
#import "SAFeedBackConsoultDetaileController.h"//重用咨询详情界面

@interface SAFeedbackProductConsoultViewController ()<UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate>

//新建咨询
@property (weak, nonatomic) IBOutlet UIImageView *createConsoultImage;
//搜索栏
@property (nonatomic, strong) UISearchBar *searchbar;

@property (nonatomic, strong) UITableView *tabview;

@end

@implementation SAFeedbackProductConsoultViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view insertSubview:self.tabview belowSubview:self.createConsoultImage];
    self.title = @"";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - custom method
//更多消息
- (void)moreMessageInformation:(UIButton *)sender {
    [sender setBackgroundImage:SAImageNamed(@"NaviBar-xiaoxi2") forState:(UIControlStateNormal)];
}

#pragma mark - view action
//设置searchBar的属性
- (void)setUpSearchBar{
    CGRect mainViewBounds = self.navigationController.view.bounds;
    self.searchbar = [[UISearchBar alloc] initWithFrame:CGRectMake(CGRectGetWidth(mainViewBounds)/2 - 10 * SAkWidth_scale - ((CGRectGetWidth(mainViewBounds)- 80 * SAkWidth_scale)/2), CGRectGetMinY(mainViewBounds) + 30 * SAkWidth_scale, CGRectGetWidth(mainViewBounds)- 80 * SAkWidth_scale, 30)];
    self.searchbar.searchBarStyle = UISearchBarStyleMinimal;
    [self.searchbar setPlaceholder:@"搜索                                            "];
    self.searchbar.delegate = self;
    //修改字体
    UITextField *searchField = [self.searchbar valueForKey:@"_searchField"];
    searchField.textColor = [UIColor blackColor];
//    [searchField setValue:[UIColor colorWithHexString:@"#f8f8f8"] forKeyPath:@"_placeholderLabel.textColor"];
    //设置背景色
    [self.searchbar setBackgroundColor:[UIColor clearColor]];
    //设置文本框背景
        [self.searchbar setSearchFieldBackgroundImage:[UIImage imageNamed:@"productSousuo"] forState:UIControlStateNormal];
    //修改放大镜
    //    UIImage *image = [UIImage imageNamed:@"sy_ss"];
    //    UIImageView *iconView = [[UIImageView alloc] initWithImage:image];
    //    iconView.frame = CGRectMake(0, 0, image.size.width , image.size.height);
    //    searchField.leftView = iconView;
    [self.navigationController.view addSubview: self.searchbar];
    
}

- (IBAction)createConsoultAction:(UITapGestureRecognizer *)sender {
    
}
#pragma mark - view cycle
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    UIButton *back = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [back setBackgroundImage:SAImageNamed(@"ljiantou") forState:(UIControlStateNormal)];
    back.frame = CGRectMake(0, 0, 10, 19);
    [back addTarget:self action:@selector(backAction) forControlEvents:(UIControlEventTouchUpInside)];
    UIBarButtonItem *leftitem = [[UIBarButtonItem alloc] initWithCustomView:back];
    self.navigationItem.leftBarButtonItem = leftitem;
    
    UIButton *messageInformation = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [messageInformation setBackgroundImage:SAImageNamed(@"NaviBar-xiaoxi1") forState:(UIControlStateNormal)];
    messageInformation.frame = CGRectMake(0, 0, 25, 25);
    [messageInformation addTarget:self action:@selector(moreMessageInformation:) forControlEvents:(UIControlEventTouchUpInside)];
    UIBarButtonItem *rightitem = [[UIBarButtonItem alloc] initWithCustomView:messageInformation];
    self.navigationItem.rightBarButtonItem = rightitem;
    [self setUpSearchBar];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.searchbar resignFirstResponder];
    [self.searchbar removeFromSuperview];
}


#pragma mark - custome method
- (void)backAction {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//    UIStoryboard *story = [UIStoryboard storyboardWithName:@"Feedback" bundle:nil];
    SAFeedBackConsoultDetaileController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"SAFeedBackConsoultDetaileController"];
    vc.title = @"产品咨询详情";
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SAFeedbackConsoultCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SAFeedbackConsoultCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;
}
#pragma mark - setter&getter
- (UITableView *)tabview {
    if (!_tabview) {
        self.tabview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SASCREEN_WIDTH, SASCREEN_HEIGHT) style:(UITableViewStylePlain)];
        self.tabview.delegate = self;
        self.tabview.dataSource = self;
        [self.tabview registerNib:[UINib nibWithNibName:@"SAFeedbackConsoultCell" bundle:nil] forCellReuseIdentifier:@"SAFeedbackConsoultCell"];
        self.tabview.showsVerticalScrollIndicator = NO;
        self.tabview.showsHorizontalScrollIndicator = NO;
        self.tabview.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tabview;
}


@end
